package com.cea.papyrus.core.actions.imports;

import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.gef.commands.Command;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IWorkbenchPart;

import com.cea.papyrus.core.PapyrusPlugin;
import com.cea.papyrus.core.commands.EMFtoGEFWrapCommand;

/**
 * Action that imports libraries package from repository
 */
public class ImportLibraryFromRepositoryAction extends ImportPackageAction {

	/** request key for the request associated to this action  */
	public final static String IMPORT_PACKAGE_FROM_LIBRARY_ACTION_REQUEST = ImportLibraryFromRepositoryAction.class.getName()+ "Request";

	/** ID of  this action */
	public final static String IMPORT_PACKAGE_FROM_LIBRARY_ACTION_ID = ImportLibraryFromRepositoryAction.class.getName()+ "ID";

	/** action used to perform this action. it comes from another plugin */ 
	protected final com.cea.papyrus.profile.ui.actions.ImporLibrariesFromRepositoryAction profileAction;

	/**
	 * Creates a new ImportLibraryFromRepositoryAction
	 * @param part that part which contains the selection
	 */
	public ImportLibraryFromRepositoryAction(IWorkbenchPart part) {
		super(part);
		setText("Import library from repository");
		setId(IMPORT_PACKAGE_FROM_LIBRARY_ACTION_ID);
		setToolTipText("Import Library from Repository");

		// icon for action
		ImageDescriptor descriptor = PapyrusPlugin.getImageDescriptor(PapyrusPlugin.UML_ICONS_16x16+"PackageImport.gif");
		setImageDescriptor(descriptor);
		setHoverImageDescriptor(descriptor);

		profileAction = new com.cea.papyrus.profile.ui.actions.ImporLibrariesFromRepositoryAction();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected boolean calculateEnabled() {
		profileAction.setSelectedElement(getSelectedPackage());
		return profileAction.getCommand(editingDomain).canExecute();
	}

	@Override
	public Command createCommand(EditingDomain editingDomain) {
		profileAction.setSelectedElement(getSelectedPackage());
		return new EMFtoGEFWrapCommand(profileAction.getCommand(editingDomain));
	}

}
